  <template>
  <!-- // 分配角色 -->
  <div>
    <el-checkbox-group v-model="roleIds">
      <el-checkbox v-for="item in roleList" :key="item.id" :label="item.id">{{item.name}}</el-checkbox>
     
    </el-checkbox-group>

    <div style="margin-top: 20px; text-align: right">
      <el-button type="primary" @click="hSave">确定</el-button>
      <el-button @click="closeDialog">取消</el-button>
    </div>
  </div>
</template>
<script>
import { assignRoles } from '@/api/employees'
import {getUserDetailById} from '@/api/user'
import { getRoles} from "@/api/settings";
export default {
    props:{
        employeeId:{
            type:String,
            required:true
        }
    },
  data() {
    return {
        // 当前选中的权限列表
      roleIds: [],
    //   当前角色的信息
      roleList:[]
    }
  },
  created() {
    this.loadRoles();
  },
  methods: {
   async hSave(){
  const res = await assignRoles({ id: this.employeeId, roleIds: this.roleIds })
  console.log('保存角色', res)
  this.$emit('success')
    },
     async loadRoles() {
      const res = await getRoles({page:1,size:1000});
      console.log(res);
     this.roleList = res.data.rows
     const info = await getUserDetailById(this.employeeId)
     console.log(info);
     this.roleIds = info.data.roleIds
    },
    closeDialog() {
this.$emit('delsuccess')
    }
  }
}
</script>